<?php
class Xigg_Plugin_HTML_AutoFormat_Main extends Xigg_Plugin
{
    function onHTMLizeNodeTeaser($id, $contentSyntax, &$teaser, &$autoParagraph, &$linkify)
    {
        if ($contentSyntax == 'HTML_AutoFormat') {
            $autoParagraph = $linkify = true;
        }
    }

    function onHTMLizeNodeBody($id, $contentSyntax, &$body, &$autoParagraph, &$linkify)
    {
        if ($contentSyntax == 'HTML_AutoFormat') {
            $autoParagraph = $linkify = true;
        }
    }

    function onHTMLizeCommentBody($id, $contentSyntax, &$body, &$autoParagraph, &$linkify)
    {
        if ($contentSyntax == 'HTML_AutoFormat') {
            $autoParagraph = $linkify = true;
            //$body = preg_replace('/\n(\w)/', '<br />\\1', $body);
/*            if (preg_match('/\n((\>).*\n)(?!(\>))/Us', "\n" . $body)) {
            	$body = substr(preg_replace('/\n(\>)+\s/', '<br />\\0', "\n" . $body), 1);
				//$body = '<blockquote>' . preg_replace('/\n(\>)+\s/', "\n", "\n" . $body . "\n") . '</blockquote>';
			}*/
        }
    }

    function onShowNodeForm(&$form, $isEdit)
    {
        $syntax =& $form->getElement('content_syntax');
        $syntax->addOption('HTML_AutoFormat', $this->_('HTML AutoFormat'));
        /*if ($syntax->getValue() == 'HTML_AutoFormat') {
            require_once dirname(__FILE__) . '/ShowNodeFormTextarea.php';
            $form->addElement(new HTML_AutoFormat_ShowNodeFormTextarea(
                                                                $form->getElement('teaser'),
                                                                10),
                              $form->getElementLabel('teaser'));
            $form->addElement(new HTML_AutoFormat_ShowNodeFormTextarea($form->getElement('body')),
                              $form->getElementLabel('body'));
        }*/
    }

    function onShowCommentForm(&$form, $isEdit)
    {
        if ($form->hasElement('content_syntax')) {
            $syntax =& $form->getElement('content_syntax');
            $syntax->addOption('HTML_AutoFormat', $this->_('HTML AutoFormat'));
            /*if ($syntax->getValue() == 'HTML_AutoFormat') {
                require_once dirname(__FILE__) . '/ShowNodeFormTextarea.php';
                $form->addElement(new HTML_AutoFormat_ShowNodeFormTextarea($form->getElement('body')),
                                  $form->getElementLabel('body'));
            }*/
        }
    }
}